function ifThrow() {
    return Math.random() > 0.55;
}


function foo() {
    return new Promise(function(f, r) {
        if (ifThrow()) r('rrr');
        else f('fff');
    });
}


foo()

.then(function f(arg) {
    console.log('now then1, arg=%s', arg);
    if (ifThrow()) throw new Error('error from then11111');
    return 'then1 done';
})

.then(function(arg) {
    console.log('now then2, arg=%s', arg);
    if (ifThrow()) throw new Error('error from then22222');
    return 'then2 done';
})

.catch(function(error) {
    console.log('catch error here', error);
    return 'catch done';
})


// can do then after catch
.then(function f(arg) {
    console.log('after catch/fail, then arg=%s', arg);
    return 'then3 done';
})